package com.yanqu.road.dao.impl.activity.WinterLove;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.winterLove.config.WinterLoveItem;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class WinterLoveItemDaoImpl extends TempDao {
    private static String getLowWinterLoveItemSql = "select * from `t_s_activity_winterlove_item` where `activityId`=? and level=1";
    public List<WinterLoveItem> getLowWinterLoveItemList(int activityId) {
        List<WinterLoveItem> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLowWinterLoveItemSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WinterLoveItem winterLoveItem = new WinterLoveItem();
                winterLoveItem.setActivityId(rs.getInt("activityId"));
                winterLoveItem.setItemId(rs.getInt("itemId"));
                winterLoveItem.setName(rs.getString("name"));
                winterLoveItem.setLevel(rs.getInt("level"));
                winterLoveItem.setType(rs.getInt("type"));
                winterLoveItem.setQuality(rs.getInt("quality"));
                winterLoveItem.setWeight(rs.getInt("weight"));
                winterLoveItem.setExtraId(rs.getInt("extraId"));
                winterLoveItem.setMaxNum(rs.getInt("maxNum"));
                list.add(winterLoveItem);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getHighWinterLoveItemSql = "select * from `t_s_activity_winterlove_item` where `activityId`=? and level=2";
    public List<WinterLoveItem> getHighWinterLoveItemList(int activityId) {
        List<WinterLoveItem> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHighWinterLoveItemSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WinterLoveItem winterLoveItem = new WinterLoveItem();
                winterLoveItem.setActivityId(rs.getInt("activityId"));
                winterLoveItem.setItemId(rs.getInt("itemId"));
                winterLoveItem.setName(rs.getString("name"));
                winterLoveItem.setLevel(rs.getInt("level"));
                winterLoveItem.setType(rs.getInt("type"));
                winterLoveItem.setQuality(rs.getInt("quality"));
                winterLoveItem.setWeight(rs.getInt("weight"));
                winterLoveItem.setExtraId(rs.getInt("extraId"));
                winterLoveItem.setMaxNum(rs.getInt("maxNum"));
                list.add(winterLoveItem);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}